package cn.zwx.learn.mybatis.example.croe.session;

import cn.zwx.learn.mybatis.example.croe.executor.Executor;

/**
 * @author zhangwenxue
 */
public class DefaultSqlSession {

    private Configuration configuration;

    private Executor executor;

    public DefaultSqlSession(Configuration configuration) {
        this.configuration = configuration;
        this.executor = configuration.newExecutor(configuration);
    }

    public <T> T getMapper(Class<T> clazz){
        return configuration.getMapper(clazz, this);
    }

    public <T> T selectList(String statement, Object[] parameter, Class pojo)  {
        String sql = configuration.getMappedStatement(statement);
        // 打印代理对象时会自动调用toString()方法，触发invoke()
        return executor.query(sql, parameter, pojo);
    }

    public Configuration getConfiguration() {
        return this.configuration;
    }
}
